/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_caja_billeteDAOImpl implements orm.dao.Tbv_caja_billeteDAO {
	public Tbv_caja_billete loadTbv_caja_billeteByORMID(int cb_id_caja_billetes) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_billeteByORMID(session, cb_id_caja_billetes);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete getTbv_caja_billeteByORMID(int cb_id_caja_billetes) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_caja_billeteByORMID(session, cb_id_caja_billetes);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByORMID(int cb_id_caja_billetes, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_billeteByORMID(session, cb_id_caja_billetes, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete getTbv_caja_billeteByORMID(int cb_id_caja_billetes, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_caja_billeteByORMID(session, cb_id_caja_billetes, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByORMID(PersistentSession session, int cb_id_caja_billetes) throws PersistentException {
		try {
			return (Tbv_caja_billete) session.load(orm.Tbv_caja_billete.class, new Integer(cb_id_caja_billetes));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete getTbv_caja_billeteByORMID(PersistentSession session, int cb_id_caja_billetes) throws PersistentException {
		try {
			return (Tbv_caja_billete) session.get(orm.Tbv_caja_billete.class, new Integer(cb_id_caja_billetes));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByORMID(PersistentSession session, int cb_id_caja_billetes, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_caja_billete) session.load(orm.Tbv_caja_billete.class, new Integer(cb_id_caja_billetes), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete getTbv_caja_billeteByORMID(PersistentSession session, int cb_id_caja_billetes, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_caja_billete) session.get(orm.Tbv_caja_billete.class, new Integer(cb_id_caja_billetes), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete[] listTbv_caja_billeteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_caja_billeteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete[] listTbv_caja_billeteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_caja_billeteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete[] listTbv_caja_billeteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_billete as Tbv_caja_billete");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_caja_billete[]) list.toArray(new Tbv_caja_billete[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete[] listTbv_caja_billeteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_billete as Tbv_caja_billete");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_caja_billete[]) list.toArray(new Tbv_caja_billete[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_billeteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_caja_billeteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_caja_billete[] tbv_caja_billetes = listTbv_caja_billeteByQuery(session, condition, orderBy);
		if (tbv_caja_billetes != null && tbv_caja_billetes.length > 0)
			return tbv_caja_billetes[0];
		else
			return null;
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_caja_billete[] tbv_caja_billetes = listTbv_caja_billeteByQuery(session, condition, orderBy, lockMode);
		if (tbv_caja_billetes != null && tbv_caja_billetes.length > 0)
			return tbv_caja_billetes[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_caja_billeteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_caja_billeteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_caja_billeteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_caja_billeteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_caja_billeteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_billete as Tbv_caja_billete");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_caja_billeteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_caja_billete as Tbv_caja_billete");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete createTbv_caja_billete() {
		return new orm.Tbv_caja_billete();
	}
	
	public boolean save(orm.Tbv_caja_billete tbv_caja_billete) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_caja_billete);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_caja_billete tbv_caja_billete) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_caja_billete);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_caja_billete tbv_caja_billete)throws PersistentException {
		try {
			if(tbv_caja_billete.getTbv_tipo_caja_billetetc_id_tipo_caja_billete() != null) {
				tbv_caja_billete.getTbv_tipo_caja_billetetc_id_tipo_caja_billete().tbv_caja_billete.remove(tbv_caja_billete);
			}
			
			orm.Tbv_maquina[] lTbv_maquinas = tbv_caja_billete.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_caja_billetecb_id_caja_billetes(null);
			}
			return delete(tbv_caja_billete);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_caja_billete tbv_caja_billete, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tbv_caja_billete.getTbv_tipo_caja_billetetc_id_tipo_caja_billete() != null) {
				tbv_caja_billete.getTbv_tipo_caja_billetetc_id_tipo_caja_billete().tbv_caja_billete.remove(tbv_caja_billete);
			}
			
			orm.Tbv_maquina[] lTbv_maquinas = tbv_caja_billete.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_caja_billetecb_id_caja_billetes(null);
			}
			try {
				session.delete(tbv_caja_billete);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_caja_billete tbv_caja_billete) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_caja_billete);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_caja_billete tbv_caja_billete) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_caja_billete);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_caja_billete loadTbv_caja_billeteByCriteria(Tbv_caja_billeteCriteria tbv_caja_billeteCriteria) {
		Tbv_caja_billete[] tbv_caja_billetes = listTbv_caja_billeteByCriteria(tbv_caja_billeteCriteria);
		if(tbv_caja_billetes == null || tbv_caja_billetes.length == 0) {
			return null;
		}
		return tbv_caja_billetes[0];
	}
	
	public Tbv_caja_billete[] listTbv_caja_billeteByCriteria(Tbv_caja_billeteCriteria tbv_caja_billeteCriteria) {
		return tbv_caja_billeteCriteria.listTbv_caja_billete();
	}
}
